package be.xios.projectquiz.statuspanels;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import javax.swing.JPanel;
import be.xios.projectquiz.game.Game;
import be.xios.projectquiz.game.Player;
import be.xios.projectquiz.game.PlayerList;

/// <summary>
/// Deze klasse is een jpanel waaorp de statussen van de spelers worden getekend
/// </summary>
/// <author>Sebastian Kubski</author>
@SuppressWarnings("serial")
public class PlayerStatusPanel extends JPanel {

	private Game game;
	private Color matrixKleur;
	
	public PlayerStatusPanel(Color matrixKleur) {
		this.game=null;
		this.matrixKleur=matrixKleur;
	}
	
	public void paintComponent(Graphics g) {
		super.paintComponent(g);
		this.setBackground(Color.BLACK);
		
		Graphics2D g2D=(Graphics2D) g;		
		g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);		

		g2D.setColor(matrixKleur);
		g2D.setFont(new Font("Arial", Font.BOLD, 12));
		
		g2D.drawRoundRect(2, 2, this.getWidth() - 5, this.getHeight() - 5, 5 , 5);
		
		if ( game == null) {
			g.drawString("No players connected", 7 , 30 );
		}
		
		else {
			TekenSpelersLijst(g);	
		}
	}
	
	/// <summary>
	/// Deze method update de spelers lijst telkens
	/// </summary>
	/// <author>Sebastian Kubski</author>
	private void TekenSpelersLijst(Graphics g) {

		PlayerList playerList = game.getPlayerList();
		
		int y = 30;
		
		for(Player p: playerList) {
			g.drawString(p.getNaam() + " " + p.getVoornaam() + " at " + p.getMyIP(), 7 , y);
			y+=20;
			g.drawString("connected and ready", 27 , y);
			y+=20;
		}
 	}

	public void setGame(Game game) {
		this.game = game;
	}	
}